﻿using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web.Http.Filters;
using Common.ResultMessage;

namespace Internal_TB.Filters
{
    public class WebApiExceptionFilterAttribute : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var res = new HttpResponseMessage(HttpStatusCode.OK);

            res.Content = new ObjectContent<BizResultMessage>(new BizResultMessage()
            {
                Msg = actionExecutedContext.Exception.Message,
                Success = false
            }, new JsonMediaTypeFormatter());

            actionExecutedContext.Response = res;

            //base.OnException(actionExecutedContext);
        }
    }
}